<?php

class Application_Model_PathsService
{
    private static $instance = null;
    private static $publicDirectory = null;
    
    public static function getInstance(){
        if (Application_Model_PathsService::$instance == null)
            Application_Model_PathsService::$instance = 
                new Application_Model_PathsService();
        $conf_logic = Zend_Registry::getInstance()->conf_logic;
        Application_Model_PathsService::$publicDirectory = $conf_logic -> path -> public_directory; 
        return Application_Model_PathsService::$instance;
    }
    
    public function get($typeDirectory, $iconDir = null, $options = null){
        $path = null;
        
        switch($typeDirectory){
            case "temp": $path = "db/tmp/"; break;
            case "news": $path = "db/news/"; break;
            case "system_textures": $path = "db/textures/systemtextures/"; break;
            case "fill_textures": $path = "db/textures/filltextures/"; break;
            case "handly_spec": $path = "db/specifications/handlys/"; break;
        }
            
        if ($path != null){
            if ($iconDir){
                $path .= "icons/";
            }
            
            if (isset($options) && isset($options['web']) && $options['web'] == true)
            return $path;
            
            $path = APPLICATION_PATH . "/../" . Application_Model_PathsService::$publicDirectory . $path;
            if (!is_dir($path) && !mkdir($path, 0777, true))
                $path = null;
        }
        return $path;
    }
}

